package promote.brozen.dubbo.providers.annotaionconfig;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;

/**
 * @author Brozen
 * @date 2020/9/2 3:08 PM
 * @email brozen@qq.com
 */
@SpringBootApplication
@EnableDubbo(scanBasePackages = "promote.brozen.dubbo.providers.api")
public class ProviderApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder()
                .web(WebApplicationType.NONE)
                .sources(ProviderApplication.class)
                .build()
                .run(args);
    }


    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("TestExportApiWithJavaConfig");
        return applicationConfig;
    }

    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("nacos://127.0.0.1:8848?namespace=484a0ac6-add3-4ea8-847d-cdefec40f5b8");
        registryConfig.setProtocol("nacos");
        registryConfig.setGroup("dev");
        return registryConfig;
    }

    @Bean("30010")
    public ProtocolConfig protocolConfig30010() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(30010);
        protocolConfig.setThreads(4);
        return protocolConfig;
    }

    @Bean("30011")
    public ProtocolConfig protocolConfig30011() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(30011);
        protocolConfig.setThreads(4);
        return protocolConfig;
    }

}
